package ihm.overlays;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

/**
 * Display a list of friends in a specific group.
 * @author Nicolas Yzet <nicolas.yzet@gmail.com>
 *
 */
public class FriendGroupOverlay extends Composite{

	private final ListElementsOverlay groups;
	private final String RETURN_BUTTON_CAPTION = "Return to the group list";
	private final Button returnButton;
	/**
	 * initialize the group list.
	 * @param father
	 */
	public FriendGroupOverlay(Composite father) {
		super(father, SWT.NONE);
		this.setLayout(new GridLayout(1, true));
		
		returnButton = new Button(this, SWT.FLAT);
		returnButton.setText(RETURN_BUTTON_CAPTION);
		
		groups = new ListElementsOverlay(this);
	}
	
	/**
	 * Add a group in the list of the ui.
	 * @param caption displayed under the picture.
	 * @param friendPicture picture of the group automaticaly resized.
	 */
	public void addFriend(String caption, Image friendPicture) {
		groups.addElement(caption, friendPicture);
	}
	
	/**
	 * Add a listener to the click event fired when a friend in a group is selected.
	 * @param listener
	 */
	public void addFriendListener(ElementListener listener) {
		groups.addElementListener(listener);
	}
	
	/**
	 * clear the list of friends displayed.
	 */
	public void clear() {
		groups.clear();
	}
	
	/**
	 * redraw the children component as well.
	 */
	@Override
	public void layout() {
		super.layout();
		groups.layout();
	}
	
	/**
	 * Wrap the selection listener of the return button.
	 * @param listener
	 */
	public void addReturnButtonSelectionListener(SelectionListener listener) {
		this.returnButton.addSelectionListener(listener);
	}
	
	
}
